package com.yukh.test.javabase.thread.pool.ex1;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.junit.Ignore;
import org.junit.Test;

public class ThreadPool {
	private final ExecutorService executor = Executors.newFixedThreadPool(2);
	
	@Ignore
	@Test
	public void noPool(){
		for(int i=0; i<1000; i++){
			new Thread() {
				public void run() {
					System.out.println("1");
					try {
						Thread.sleep(2000);
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			}.start();
		}
	}
	
	@Test
	public void javaPool(){
		for(int i=0; i<1000; i++){
			executor.execute(new Runnable() {
				public void run() {
					try {
						System.out.println("1");
						Thread.sleep(2000);
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			});	
		}
	}
}
